package cn.wolfcode.controller;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.service.IEmployeeService;
import cn.wolfcode.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("employees")
public class EmployeeController {
    @Autowired
    private IEmployeeService employeeService;
    @GetMapping("/list")
    public List< Employee > list(){

       return employeeService.list();
    }
    @GetMapping("/detail")
    public Employee detail(Long id){

        return  employeeService .getById(id);
    }
    @PostMapping("/save")
    public AjaxResult save(Employee employee){
        employeeService.save(employee);
        return  new AjaxResult().success();
    }
    @PutMapping("/update")
    public AjaxResult update(Employee employee){
        employeeService.updateById(employee);
        return  new AjaxResult().success();
    }
    @DeleteMapping("/delete")
    public AjaxResult delete(Long id){
        employeeService.removeById(id);
        return  new AjaxResult().success();
    }
}
